<?php
/**
 * Created by PhpStorm.
 * User: ycp
 * Date: 2019/5/23
 * Time: 22:23
 */

namespace app\api\controller;


class GoodsCategory extends ApiCommon
{
    protected $cateTable = 'store_goods_cate';
    protected $goodsTable = 'store_goods';


    public function __construct()
    {
        parent::__construct();
    }

    //获取全球省市区
    public function index()
    {
       $cateData = db($this->cateTable)->field('id,title')->where(['is_deleted' => 0])->order('sort desc')->select();
       $cateIds = array_column($cateData,'id');
       $goodsData = db($this->goodsTable)->field('id,cate_id,title,logo')->where(['cate_id' => $cateIds, 'status' => 1, 'is_deleted' => 0])->order('sort desc')->select();

       $res['cate'] = $cateData;
       foreach ($cateData as $key => $datum){
           $datum['pid'] = $datum['id'];
           $res['cateTitle'][] = $datum;
       }

       foreach ($goodsData as $key =>$goodsDatum){
           $goodsDatum['pid'] = $goodsDatum['cate_id'];
           $goodsDatum['picture'] = $goodsDatum['logo'];
           $res['goods'][] = $goodsDatum;
       }
        $this->success('', $res);

    }
}